package com.second.oa.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.second.oa.dao.EmployeeDao;
import com.second.oa.domain.Department;
import com.second.oa.domain.Employee;


public class EmployeeDaoImpl extends BaseDaoImpl<Employee> implements EmployeeDao {

	public void add(Employee emp) throws SQLException {

	}

	public void update(Employee emp) throws SQLException {

	}

	public void delete(String id) throws SQLException {

	}
	
	/**
	 * 查询一条记录
	 * @param sql 查询SQL
       <pre>
     	select
		  e.id e_id,
		  e.code e_code,
		  e.password e_password,
		  e.name e_name,
		  e.gender e_gender,
		  e.birthday e_birthday,
		  e.depart e_depart,
		  e.job e_job,
		  e.introduction e_introduction,
		  e.phone e_phone,
		  e.email e_email,
		  e.qq e_qq,
		  e.wechat e_wechat,
		  d.id d_id,
		  d.code d_code,
		  d.name d_name,
		  d.remark d_remark,
		  d.parent d_parent
		
		from
		  t_employee e 
		  left join t_department d on e.depart = d.id
		where
		  e.id = ?
        </pre>
	 */
	@Override
	public Employee transform(ResultSet res) throws SQLException {
		
		Department depart = null;
		if(res.getString("d_id") != null) {
			depart = new Department(res.getString("d_id"), 
					null, res.getString("d_code"), 
					res.getString("d_name"), 
					res.getString("d_remark"));
		}
			
		Employee emp = new Employee(res.getString("e_id"), depart, 
				res.getString("e_code"),
				res.getString("e_password"),
				res.getString("e_name"),
				res.getString("e_gender"),
				res.getTimestamp("e_birthday"),
				res.getString("e_job"),
				res.getString("e_introduction"),
				res.getString("e_phone"),
				res.getString("e_email"),
				res.getString("e_qq"),
				res.getString("e_wechat")
			);
		
		return emp;
	}
}
